/**
	例句听力 例句翻译  组句用的js
	$("#wordsTable")  选项ul
	$("#sentence") 选中后放置的位置
**/
	/**
	 * 启动时候初始化配置  添加事件
	 * @return
	 */
	function initCofig(){
		/*****填空区加事件*****/
		$(document).on("click","#sentence span.word",function(event){
			if(wordLoader.step==0||wordLoader.step==3){
				jQuery("#li"+this.id).removeClass("visibility");
				jQuery("#li"+this.id).data("selected","false");
				jQuery(this).before("<span class='span_null'></span>");
				jQuery(this).remove();
			}
		}).on("mouseover","#sentence span.word",function(event){
		}).on("mouseout","#sentence span.word",function(event){
		});
		/***为选项卡添加事件***/
		jQuery(document).on("click","#wordsTable li",function(event){
			if(wordLoader.step == 3){//训练页面点击单词停止卡拉OK效果（听力+翻译）
				wordLoader.pauseSound();
			}
			var spanArray = $("#sentence").find("span.span_null");//所有的空格子
			var liObj = jQuery(this);//当前li对象
			var srcObj = liObj.find("span");//li中的span对象
			var selectWord=srcObj.html();//选择的单词
			if(wordLoader.step==0){//组句
				if(liObj.data("selected")=="true" || srcObj.size()<=0){  // 空格子， 和已经被点过的格子不再处理
					return;
				}else{
					for(var i=0;i<spanArray.length;i++){
						var o = jQuery(spanArray[i]);
						if(o.data("value")=="true"){
						}else{ // 连点问题 未处理    增加 td 状态标记
							liObj.data("selected","true");
							o.data("value","true");
							liObj.addClass("visibility");
							var cloneObj = srcObj.clone();
							cloneObj.prop("id","_"+srcObj.prop("id"));
							o.after(cloneObj);
							o.remove();
							if($("#sentence").find("span.span_null").size()<=0){
								setTimeout(submitAnswer,100);//提交
							}
							break;
						}
					}
				}
			}else if(wordLoader.step==3){//训练  抄写
				var nullSpanLength = spanArray.length;//空span的长度
				var array=[];//正确单词列表
				for(i=0;i<wordLoader.word.words.length;i++){
					var word = wordLoader.word.words[i];
					if(word.length==1 && specChar.test(word)){ // 标点符号 处理 
					}else{ // 单词处理
						array.push(word);
					}
				}
				var wordsLength=array.length;//总单词长度
				if(selectWord==array[wordsLength-nullSpanLength]){
					//$("#sentenceEn").hide();
					$("#sentenceEn").css("visibility","hidden");
					var o=jQuery(spanArray[0]);
					liObj.addClass("visibility");
					var cloneObj = srcObj.clone();
					cloneObj.prop("id","_"+srcObj.prop("id"));
					o.after(cloneObj);
					o.remove();
					if($("#sentence").find("span.span_null").size()<=0){
						//setTimeout(function(){//自动保存
							//wordLoader.saveStatus();
						//},300);
						//不自动提交  让用户自己来提交
						$("#sentence span").addClass("wordSpellColor");
						$("#delete").hide();
						$("#next").show();	
						$("#wordsTable").hide();
						//if(deviceType==14){
						//	$("#sentenceEnInitialLocal").append($("#sentenceEn"));
						//}
						$(".play").show();
						$("#sentenceZh").show();
						//$("#sentenceEn").show();
						//$("#sentenceEn").css("visibility","");
						//jQuery("#rightImg").show();
						playmp3(rightSound);
						wordLoader.step=2;
					}
					nullSpanLength--;
				}else{//抄错了
					//$("#sentenceZh").hide();
					//$("#sentenceEn").show();
					$("#sentenceEn").css("visibility","");
					playmp3(wrongSound);
					$("#sentenceEn .word").eq((wordsLength-nullSpanLength)).addClass("red");
					setTimeout(function(){
						$("#sentenceEn .word").eq((wordsLength-nullSpanLength)).removeClass("red");
					},1000);
				}
			}
		});
	}
	/**
		初始化选项格子
	**/
	function initCell(wordIndexArray){
		$("#wordsTable").empty();
		var num = wordIndexArray.length;
		var tempIndex=0;
		for(var i=0;i<num;i++){
			tempIndex = Math.round(Math.random()*(wordIndexArray.length-1));
			$("#wordsTable").append("<li id='li_w_"+i+"'><span id='w_"+i+"' class='word'>"+
						wordLoader.word.words[wordIndexArray[tempIndex]]+"</span></li>");
			wordIndexArray.remove(tempIndex);
		}
	}
	/**
		重新组句
	**/
	function resetSentence(){
		$("#sentence span.specChar").addClass("wordSpellColor");
		if($("#sentence").find("span.word").size()<=0){
			return;	
		}else{
			jQuery.each($("#sentence").find("span.word"),function(i,item){
				jQuery("#li"+this.id).removeClass("visibility");
				jQuery("#li"+this.id).data("selected","false");
				jQuery(this).before("<span class='span_null'></span>");
				jQuery(this).remove();
			});
		}
	}
	
		/**
		句子验证流程
		去除 span 元素
		去掉句子中的所有空格符号 模糊验证
	**/
	function checkUserSentence(){
		var tmp = $("#sentence").clone();
		//答错的单词标红显示
		var answerSpan = $("#sentence").find("span");
		for(i=0;i<answerSpan.length;i++){
			if(jQuery(answerSpan[i]).attr("class")=="span_null"){
				break;
			}
			if(jQuery(answerSpan[i]).attr("class")=="specChar"){
				//标点符号颜色为绿色
				//jQuery(answerSpan[i]).css("color","#00bb98");
				continue;
			}
			var word = wordLoader.word.words[i];
			if(word == jQuery(answerSpan[i]).text()){
				//答对的单词颜色为绿色
				//jQuery(answerSpan[i]).css("color","#00bb98");
				continue;
			}else{
				jQuery(answerSpan[i]).addClass("red");
			}
		}
		
		jQuery.each(tmp.find("span.span_null"),function(i,item){
			obj = jQuery(this).remove();
		});
		
		var wordSpan = tmp.find("span.word");
		jQuery.each(wordSpan,function(i,item){
			obj = jQuery(this);
			obj.after(obj.html()).remove();
		});
		
		jQuery.each(tmp.find("span.specChar"),function(i,item){
			obj = jQuery(this);
			obj.before(obj.html()).remove();
		});
		
		str = tmp.html().replace(/\s/g,"");
		str = str.replace(/(&nbsp;)/g,"");
		var context = wordLoader.word.example_en_US;
		context = context.replace(/\s/g,"");
		if(str == context){
			jQuery("#rightImg").show();
			return true;
		}else{
			jQuery("#wrongImg").show();
			return false;
		}
	}
	
	/**
		为Array对象添加属性和方法
		删除Array对象的index的值
		barray.remove(1);
	**/
	Array.prototype.remove=function(dx){
	    if(isNaN(dx)||dx>this.length){
	    	return false;
	    }
	    for(var i=0,n=0;i<this.length;i++){
	        if(this[i]!=this[dx]){
	            this[n++]=this[i];
	        }
	    }
	    this.length-=1;
	};
	